#ifndef _CONFIG_H_
#define _CONFIG_H_
#include <map>
#include <string>
#include "CCObject.h"

using namespace std;
USING_NS_CC;

#pragma warning(disable:4172)

class TiXmlElement;

class Config: public CCObject
{
public:
	class DataItem : public map<string,string>
	{
	public:
		const string&		operator[](const string& key) const
		{
			DataItem::const_iterator it = find(key);
			if( it != this->end() )
			{
				return it->second;
			}
			return NULL;
		}
	};

	typedef pair<string, string>		StrPair;
	//typedef map<string, string>			DataItem;
	typedef pair<string, DataItem>		StrDataItemPair;
	typedef map<string, DataItem>		DataTable;

	Config();
	virtual ~Config();

	static Config*		configWithFile( const char * file );
	static Config*		configWithXml( TiXmlElement* xml );
	bool				init( const char * file );
	bool				init( TiXmlElement * xml );
	const DataItem&		operator[](const string& key);
	const DataItem&		operator[](const string& key) const;
	const DataItem&		getItem(const string&key);
	const DataItem&		getItem(const string&key) const;
	DataTable&			getItems();


protected:

	DataTable							m_table;
};

#endif